package com.hl.icd.service.impl;

import com.github.pagehelper.PageHelper;
import com.hl.icd.bean.ICD;
import com.hl.icd.bean.ICD10To11Mapping;
import com.hl.icd.bean.Mapping;
import com.hl.icd.dao.ICD10To11MappingDao;
import com.hl.icd.dao.MappingDao;
import com.hl.icd.service.MapperService;
import com.hl.icd.utils.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MapperServiceImpl implements MapperService {

    @Autowired
    private ICD10To11MappingDao icd10To11MappingDao;

    @Autowired
    private MappingDao mappingDao;

    @Override
    public List<Mapping> mapperQuery(int pageNum, int pageSize, Mapping mapping) {
        PageHelper.startPage(pageNum,pageSize);
        return mappingDao.getMapperListByCondition(mapping);
    }

    @Override
    public String insertOne(Mapping mapping) {
        String message="error";
        mapping.setId(UUIDUtil.getUUID());
        int res = mappingDao.insert(mapping);
        if(res == 1){
            message = "success";
        }
        return message;
    }

    @Override
    public String deleteOneById(String id) {
        String message="error";
        int res = mappingDao.deleteByPrimaryKey(id);
        if(res == 1){
            message = "success";
        }
        return message;
    }

    @Override
    public String updateOne(Mapping mapping) {
        String message="error";
        int res = mappingDao.updateMapper(mapping);
        if(res == 1){
            message="success";
        }
        return message;
    }

    @Override
    public String deleteBatch(List<String> ids) {
        String message="success";
        int res=0;
        for (String id : ids) {
            res = mappingDao.deleteByPrimaryKey(id);
            if(res!=1){
                message = "error";
                return message;
            }
        }
        return message;
    }


}
